<?php

################################################
$msg = '';
$mb = 1.5;//MB
$allowedSize = $mb*1024*1024;//Bytes
$allowedExtn = array('doc','docx','jpeg','jpg');//try with pdf
$upload_dir = "./uploads";
#################################################


echo '<pre>';
print_r($_FILES);
if(isset($_FILES['avatar']['error'])){
  if($_FILES['avatar']['error']==0){
    if($_FILES['avatar']['size'] > $allowedSize){
      $msg = "1111Please upload file with $mb MB max.";
    } else {
      $fileInfo = pathinfo($_FILES['avatar']['name']);
      print_r($fileInfo);
      if(in_array($fileInfo['extension'],$allowedExtn)) {

        if(is_uploaded_file($_FILES['avatar']['tmp_name'])){
          $src = $_FILES['avatar']['tmp_name'];
          $fileName = $_FILES['avatar']['name'];
          $dest = $upload_dir.'/'.$fileName;
          if(move_uploaded_file($src,$dest)){
            $msg = "file ($fileName) uploaded successfully";
          } else {
            $msg = "Please check your upload directory permission.<br>Please try again.";
          }
        } else {
          $msg = "There might be some error during upload.Please try again.";
        }

      } else {
        $msg = "Please upload file with valid extn ".implode(',',$allowedExtn).'.';
      }

    }
  } else {
    $msg = "2222Please upload file with $mb MB max.";
  }
}
echo '<h1><em>'.$msg.'</em></h1>';
?>
<form action="" method="post"
enctype="multipart/form-data">
  Avatar : <input type="file" name="avatar"/><br>
  <input type="submit" value="Upload Data !!" />
</form>
